package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.db.User;
import com.tanhua.dubbo.mapper.UserMapper;
<<<<<<< HEAD
=======
import org.apache.dubbo.config.annotation.Reference;
>>>>>>> acc7004 (第4天到第8天)
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * @version 1.0
 * @author： xtr
 * @date： 2021-03-04 21:06
 */
@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;
    /**
     * 新增用户
     * @param user
     * @return
     */
    @Override
    public Long save(User user) {
        user.setCreated(new Date());
        user.setUpdated(new Date());
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 通过手机号查询
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",mobile);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    /**
     * 更新用户信息
     *
     * @param userId
     */
    @Override
    public void update(String phone,Long userId) {
        User user = new User();
        user.setId(userId);
        user.setMobile(phone);
        userMapper.updateById(user);
    }
}
